/*
 * Copyright 2014 Alex Curran
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.amlcurran.showcaseview;

import ohos.agp.render.BlendMode;
import ohos.agp.render.Canvas;
import ohos.agp.render.Texture;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.media.image.PixelMap;

class NewShowcaseDrawer extends StandardShowcaseDrawer {
    private static final float ALPHA_10_PERCENT = 0.1f;
    private float outerRadius;
    private float innerRadius;

    NewShowcaseDrawer(Context context) {
        super(context);
        try {
            outerRadius = context.getResourceManager().getElement(ResourceTable.Float_showcase_radius_outer).getFloat();
            innerRadius = context.getResourceManager().getElement(ResourceTable.Float_showcase_radius_inner).getFloat();
        } catch (Exception e) {
            LocalHiLog.warn("ShowcaseView", "showcase_radius_inner or showcase_radius_outer not found");
        }
    }

    @Override
    public void setShowcaseColour(int color) {
        eraserPaint.setColor(new Color(color));
    }

    @Override
    public void drawShowcase(PixelMap buffer, float positionX, float positionY, float scaleMultiplier) {
        Texture texture = new Texture(buffer);
        Canvas bufferCanvas = new Canvas(texture);
        eraserPaint.setBlendMode(BlendMode.SRC);
        eraserPaint.setAlpha(ALPHA_10_PERCENT);
        bufferCanvas.drawCircle(positionX, positionY, outerRadius, eraserPaint);
        eraserPaint.setAlpha(0);
        bufferCanvas.drawCircle(positionX, positionY, innerRadius, eraserPaint);
    }

    @Override
    public int getShowcaseWidth() {
        return (int) (outerRadius * 2);
    }

    @Override
    public int getShowcaseHeight() {
        return (int) (outerRadius * 2);
    }

    @Override
    public float getBlockedRadius() {
        return innerRadius;
    }

}
